package com.baby.publish;

import com.baby.utils.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {

    public static void main(String[] args) throws IOException, TimeoutException {
        //获取connection对象
        Connection connection = ConnectionUtil.getConnection();
        //2.获取通道channel
        Channel channel = connection.createChannel();
        //3.创建一个交换机
        //String exchange, String type)
        //第一个参数：exchange:表示交换机名称,第二个参数：type交换机类型
        channel.exchangeDeclare("pubsub_exchange","fanout");
        //4.发布消息
        channel.basicPublish("pubsub_exchange","",null,"呼叫baby..".getBytes());
        //5.释放资源
        channel.close();
        connection.close();
    }

}
